package com.hmall.zookeeper.Impl;

import com.hmall.zookeeper.ServiceRegistry;
import com.hmall.zookeeper.utils.CuratorUtils;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.net.InetSocketAddress;

/**
 * 服务注册
 * Zookeeper实现
 */
@Component
public class ZkServiceRegistryImpl implements ServiceRegistry {


    @Override
    public void registerService(String rpcServiceName, InetSocketAddress address) {
        String servicePath =  "/" + rpcServiceName + address.toString();
        CuratorFramework zkClient = CuratorUtils.getZkClient();
        CuratorUtils.createPersistentNode(zkClient, servicePath);
    }
}
